package com.litongjava.jfina.undertow.servet.config;

import java.util.function.Consumer;

import com.jfinal.server.undertow.WebBuilder;
import com.litongjava.jfina.undertow.servet.listener.Test01ServletContextLocalListener;
import com.litongjava.jfina.undertow.servet.servlet.UserServlet;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class WebXmlConfig implements Consumer<WebBuilder> {

  public void accept(WebBuilder builder) {
    String name = Test01ServletContextLocalListener.class.getName();
    log.info("add listener:{}", name);
    builder.addListener(name);

    addUserServlet(builder, "/user");

  }

  private void addUserServlet(WebBuilder builder, String urlPattern) {
    String name = UserServlet.class.getName();
    String simpleName = UserServlet.class.getSimpleName();
    log.info("add servlet:{}", simpleName);
    builder.addServlet(simpleName, name);
    builder.addServletMapping(simpleName, urlPattern);
  }
}